package main

import (
	"fmt"
	"github.com/pelletier/go-toml/v2"
	"os"
	"time"
)

type Content struct {
	Date     time.Time
	English  []string
	Cs       []string
	Politics []string
	Math     []string
}

type Contents struct {
	Content []Content
}

func shouldReview(contentDate, currentDate time.Time) bool {
	daysSince := int(currentDate.Sub(contentDate).Hours() / 24)

	// Ebbinghaus intervals: 1, 2, 4, 7, 15, 30 days
	reviewDays := []int{1, 2, 4, 7, 15, 30}

	for _, day := range reviewDays {
		if daysSince == day {
			return true
		}
	}
	return false
}

func main() {
	// 读取 review.toml 文件
	homeDir, err := os.UserHomeDir()
	if err != nil {
		panic(err)
	}
	data, err := os.ReadFile(homeDir + "/review.toml")
	if err != nil {
		fmt.Println("Error reading file:", err)
		return
	}

	// 解析 TOML 数据
	var contents Contents
	if err := toml.Unmarshal(data, &contents); err != nil {
		fmt.Println("Error unmarshalling TOML:", err)
		return
	}

	// 获取当前日期
	currentDate := time.Now()

	// 计算应该复习的内容
	var xs []Content
	for _, content := range contents.Content {
		if shouldReview(content.Date, currentDate) {
			xs = append(xs, content)
		}
	}
	fmt.Println("Content to review for today:")
	fmt.Println("English:")
	for _, x := range xs {
		for _, item := range x.English {
			fmt.Println("▶", item)
		}
	}
	fmt.Println("Cs:")
	for _, x := range xs {
		for _, item := range x.Cs {
			fmt.Println("▶", item)
		}
	}
	fmt.Println("Politics:")
	for _, x := range xs {
		for _, item := range x.Politics {
			fmt.Println("▶", item)
		}
	}
	fmt.Println("Math:")
	for _, x := range xs {
		for _, item := range x.Math {
			fmt.Println("▶", item)
		}
	}
}
